package io.hilo.example.biz01.web;

import org.hilo.boot.core.BaseMsg;
import org.hilo.boot.core.exception.AppException;
import org.jretty.apibase.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import io.hilo.example.biz01.pojo.LoginUser;

/**
 * Controller Demo
 * 
 * @author xxxx
 * @since 2023-10-12
 */
@Controller
@RequestMapping("/app2")
public class DemoPlainController {
    
    @RequestMapping("/hello")
    public Result<?> hiPlainBody(String world, String hello) {
        if (world != null && world.equalsIgnoreCase("error")) {
            throw new AppException(BaseMsg.UNDEFINED_ERR);
        }
        return Result.success("springboot framework running! hello " + world);
    }

    @RequestMapping("/resbody")
    @ResponseBody
    public Result<?> hiResponseBody(String world, String hello) {
        if (world != null && world.equalsIgnoreCase("error")) {
            throw new AppException(BaseMsg.UNDEFINED_ERR);
        }
        return Result.success("springboot framework running! hello " + world);
    }

    /**
     * hiRequestBody <br/>
     * curl -H "Content-Type: application/json" -X POST http://localhost:8080/app/hi?qs=66
     */
    @RequestMapping("/hi")
    public Result<?> hiRequestBody(@RequestBody(required = false) LoginUser test) {
        if (test != null) {
            return Result.success("springboot framework running! hello " + test.getUsername());
        }
        return Result.success("springboot framework running! hello " + null);
    }

    /**
     * hiVoid <br/>
     * curl -H "Content-Type: application/json" -X POST http://localhost.com:8080/app/void?qs=66
     */
    @RequestMapping("/void")
    @ResponseBody
    public void hiVoid(@RequestBody(required = false) LoginUser test) {

    }

}
